cmake_minimum_required(VERSION 3.14)
project(boost-beast-demo)

message(STATUS "PROJECT_NAME: ${PROJECT_NAME}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(FETCHCONTENT_QUIET OFF)
set(CMAKE_PROGRESS_MULTI_LINE ON)

option(BOOST_FORCE_FETCH "Force re-download Boost submodules" OFF)

include(FetchContent)

FetchContent_Declare(
    Boost
    GIT_REPOSITORY https://github.com/boostorg/boost.git
    GIT_TAG boost-1.86.0
    GIT_SUBMODULES
        "libs/align"
        "libs/asio"
        "libs/assert"
        "libs/bind"
        "libs/beast"
        "libs/config"
        "libs/container"
        "libs/container_hash"
        "libs/core"
        "libs/endian"
        "libs/intrusive"
        "libs/mp11"
        "libs/optional"
        "libs/preprocessor"
        "libs/smart_ptr"
        "libs/static_assert"
        "libs/static_string"
        "libs/system"
        "libs/throw_exception"
        "libs/type_index"
        "libs/type_traits"
        "libs/winapi"
        "libs/context"
        "libs/coroutine"
        "libs/date_time"
        "libs/move"
        "libs/utility"
        "libs/numeric/conversion"
        "libs/mpl"
        "libs/logic"
        "libs/describe"
        "libs/io"
        "libs/predef"
    GIT_PROGRESS ON
)

# 清除旧下载
if(BOOST_FORCE_FETCH)
    if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/_deps/boost-src")
        message(STATUS "BOOST_FORCE_FETCH=ON, removing old boost-src...")
        file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/_deps/boost-src")
    endif()
endif()

FetchContent_GetProperties(Boost)
if(NOT Boost_POPULATED)
    FetchContent_Populate(Boost)
    message(STATUS "boost_SOURCE_DIR: ${boost_SOURCE_DIR}")
endif()

add_executable(${PROJECT_NAME} main.cpp)

target_include_directories(${PROJECT_NAME} PRIVATE
    ${boost_SOURCE_DIR}/libs/align/include
    ${boost_SOURCE_DIR}/libs/asio/include
    ${boost_SOURCE_DIR}/libs/assert/include
    ${boost_SOURCE_DIR}/libs/bind/include
    ${boost_SOURCE_DIR}/libs/beast/include
    ${boost_SOURCE_DIR}/libs/config/include
    ${boost_SOURCE_DIR}/libs/container/include
    ${boost_SOURCE_DIR}/libs/container_hash/include
    ${boost_SOURCE_DIR}/libs/core/include
    ${boost_SOURCE_DIR}/libs/endian/include
    ${boost_SOURCE_DIR}/libs/intrusive/include
    ${boost_SOURCE_DIR}/libs/mp11/include
    ${boost_SOURCE_DIR}/libs/optional/include
    ${boost_SOURCE_DIR}/libs/preprocessor/include
    ${boost_SOURCE_DIR}/libs/smart_ptr/include
    ${boost_SOURCE_DIR}/libs/static_assert/include
    ${boost_SOURCE_DIR}/libs/static_string/include
    ${boost_SOURCE_DIR}/libs/system/include
    ${boost_SOURCE_DIR}/libs/throw_exception/include
    ${boost_SOURCE_DIR}/libs/type_index/include
    ${boost_SOURCE_DIR}/libs/type_traits/include
    ${boost_SOURCE_DIR}/libs/winapi/include
    ${boost_SOURCE_DIR}/libs/context/include
    ${boost_SOURCE_DIR}/libs/coroutine/include
    ${boost_SOURCE_DIR}/libs/date_time/include
    ${boost_SOURCE_DIR}/libs/move/include
    ${boost_SOURCE_DIR}/libs/utility/include
    ${boost_SOURCE_DIR}/libs/numeric/conversion/include
    ${boost_SOURCE_DIR}/libs/mpl/include
    ${boost_SOURCE_DIR}/libs/logic/include
    ${boost_SOURCE_DIR}/libs/describe/include
    ${boost_SOURCE_DIR}/libs/io/include
    ${boost_SOURCE_DIR}/libs/predef/include
    ${boost_SOURCE_DIR}
)

target_link_libraries(${PROJECT_NAME} PRIVATE
    $<$<PLATFORM_ID:Linux>:pthread>
    $<$<PLATFORM_ID:Windows>:ws2_32>
)